﻿@page "/login"
@using daonaite.MasaUi.Util
@using daonaite.Model.system.login
@using daonaite.MasaUi.Api
@using daonaite.MasaUi.Util
@layout LoginLayout
@inject HttpHelp http
@inject apiLogin loginurl
<MCard Class="mx-auto my-16 pb-8" Width="600" Elevation="20">
    <MImage Src="https://cdn.masastack.com/stack/images/website/masa-blazor/cards/sunshine.jpg" Height="200"></MImage>
    <MCardTitle Class="d-flex justify-center">
        欢迎使用刀奈特管理系统
    </MCardTitle>
    <MForm Class="mx-4">
        <MTextField @bind-Value="form.username" Label="用户名" Placeholder="请输入用户名"></MTextField>
        <MTextField @bind-Value="form.username" Label="密码" Placeholder="请输入密码"></MTextField>
        <div class="d-flex align-center">
            <MTextField Class="mr-2" @bind-Value="form.yanzhengma" Label="验证码" Placeholder="请输入验证码"> </MTextField>
            <MImage Src=@tupian Height="45"></MImage>
        </div>
        <MButton Block Color="primary">登录</MButton>

    </MForm>
</MCard>

@code {
    Dto_login form = new Dto_login();
    string tupian = "";
    protected override async Task OnInitializedAsync()
    {

        await base.OnInitializedAsync();
        await getyanzhengmaAsync();
    }

    private async Task getyanzhengmaAsync()
    {
        var result = await http.getAsync<string>(loginurl.getImage);
        if (result.Code == 200)
        {
            form.code = result.Data;
            tupian = $"data:image/jpg;base64,{result.Message}";
        }
    }

    private async void OnFinish(EditContext editContext)
    {
        var result = await http.posttAsync<string, Dto_login>(loginurl.denglu, form);
        if (result.Code == 200)
        {
        }
    }
}
